/**
 * @Auther: wangliuyang
 * @Date: 2021/4/19 22:32
 * @Description: 61. 旋转链表
 */
public class Solution_61 {
    public ListNode rotateRight(ListNode head, int k) {
        if (head == null || head.next == null) return head;
        ListNode hair = new ListNode(-1);
        hair.next = head;
        ListNode cur = hair;
        int length = 0;
        while (cur.next != null) {
            cur = cur.next;
            length++;//记录链表长度
        }
        cur.next = head;
        k = k % length;
        int count = ((length - 1) * k) % length;
        for (int i = 0; i < count; i++) {
            head = head.next;
        }
        cur = head;
        while (cur.next != head) {
            cur = cur.next;
        }
        cur.next = null;
        return head;
    }
}
